<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit :isheader="isheader">
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <a-button type="primary" icon="plus" @click="add">{{$ti18('rxList.add','新增')}}</a-button>
            <a-button v-if="editEnable && selectedRowKeys.length > 0" type="primary" icon="edit" @click="editOne"
              >{{$ti18('rxList.editBtn','编辑')}}</a-button
            >
            <a-dropdown v-if="removeEnable && selectedRowKeys.length > 0">
              <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
            </a-dropdown>
          </div>
          <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
        </div>
        <div  btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel" @close="closeSearchbar">
          <a-form :layout="colLayout">
            <a-row :gutter="24">
              <a-col :span="colSpan">
                    <a-form-item :label="i18n('form.name','名称')">
                      <a-input :placeholder="i18n('form.name','名称','input')" v-model="queryParam.Q_NAME__S_LK" />
                    </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <rx-grid
          ref="table"
          :bordered="isBorder"
          :allowRowSelect="true"
          :multiSelect="true"
          :columns="columns"
          :defaultPageSize="10"
          url="/api-system/system/core/sysAuthManager/query"
          :queryParam="queryParam"
          data-field="result.data"
          :pageSizeOptions="['10', '30', '40']"
          id-field="id"
          @selectChange="onSelectChange"
        >
          <span slot="isLog" slot-scope="{ text, record, index }" >
               <a-tag :color="statusMap[text].color">
                  <span>{{ statusMap[text].text }}</span>
               </a-tag>
          </span>
          <span slot="enable" slot-scope="{ text, record, index }" >
              <a-tag :color="statusMap[text].color">
                  <span>{{ statusMap[text].text }}</span>
               </a-tag>
          </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="editEnable" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
            <span v-if="removeEnable" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
            <span @click="onRowClick(record)">{{$ti18('rxList.detailBtn','明细')}}</span>
            <span @click.stop="assignApp(record)">{{i18n('list.authorize','授权')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
import SysAuthManagerApi from '@/api/system/core/sysAuthManager'
import SysAuthManagerEdit from './SysAuthManagerEdit'
import { BaseList, Util } from "@lowcode/jpaas-common-lib"
import SysAuthManagerGet from './SysAuthManagerGet'
import SysAppGrant from './SysAppGrant'
import SysAppAuthApi from "@/api/system/core/sysAppAuth";
export default {
  name: 'SysAuthManagerList',
  mixins: [BaseList],
  data() {
    return {
      columns: [
        {
          title: this.$ti18('rxList.index','序号'),
          type: 'indexColumn',
          width: 40,
          dataIndex: 'serial',
          scopedSlots: { customRender: 'serial' },
        },
        { title: this.i18n('form.name','名称'), dataIndex: 'name', width: 150 },
        { title: this.i18n('form.isLog','记录日志'), dataIndex: 'isLog', width: 80 , scopedSlots: { customRender: 'isLog' } },
        { title: this.i18n('form.enabled','启用'), dataIndex: 'enable', width: 80 , scopedSlots: { customRender: 'enable' } },
          {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', sorter: true, sortField: 'CREATE_TIME_', width: 150},
        { title: this.$ti18('rxList.action','操作'), width: 160 , dataIndex: 'action', scopedSlots: { customRender: 'action' } },
      ],
      component: SysAuthManagerEdit,
      comment: this.i18n('list.comment','应用接口授权管理表'),
      widthHeight: ['800px', '600px'],
      statusMap: {
            true: { color: 'green', text: this.i18n('form.yes','是') },
            false: { color: 'red', text: this.i18n('form.no','否') },
      },
    }
  },
  methods: {
    i18n(name,text,key){
        return this.$ti18(name,text,"SysAuthManager",key);
    },
    delById(ids) {
      return SysAuthManagerApi.del({ ids: ids.join(',') })
    },
    getListByParams(parameter) {
      return SysAuthManagerApi.query(parameter)
    },
    onRowClick(record) {
      var conf = {
        pkId: record.pkId,
        component: SysAuthManagerGet,
        title: "[" +record.name +"]" + this.i18n('list.authorizeDetails','授权明细'),
        widthHeight: this.widthHeight,
      }
      this.handleEdit(conf)
    },
    assignApp(record) {
      var conf = {
        curVm: this,
        data: { pkId: record.id },
        max:true,
        component: SysAppGrant,
        title: record.name + " " + this.i18n('list.authorize','授权'),
      }
      Util.open(conf, function (action,data) {
          if(action!='ok') return;
          SysAppAuthApi.saveSysAppAuth(Object.assign(data),record.id).then(res=>{
          });
      })
    },
    search() {
      this.$refs.table.loadData()
    },
    cancel() {
      this.resetSearch()
    },
    closeSearchbar(){
      //关闭过滤弹窗；（点击X触发）
      this.fitSearch = false ;
    },
  },
}
</script>
<style scoped>

</style>

